'use strict';
const dayjs = require("dayjs");
module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;
    const Model = app.model.define(
      'projectComment',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            anony: {type: INTEGER, allowNull: false, defaultValue: 1, comment: '是否匿名'},
            order_id: {type: INTEGER, allowNull: true, comment: '订单'},
            order_no: {type: STRING(255), allowNull: false, comment: '订单号'},
            project_id: {type: INTEGER, allowNull: false, comment: '项目'},
            member_id: {type: INTEGER, allowNull: false, comment: '用户'},
            score: {type: INTEGER, allowNull: false, defaultValue: 0, comment: '评分'},
            comment: {type: STRING(255), allowNull: false, comment: '评论'},
            status: {type: INTEGER, allowNull: false, defaultValue: 1, comment: '审核状态'},
            is_del: {type: INTEGER, allowNull: false, defaultValue: 0, comment: '是否删除'},
          create_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          },

      },
      {
          tableName: 'project_comment',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    Model.associate = function() {
        app.model.ProjectComment.belongsTo(app.model.Goods, { foreignKey: 'project_id', targetKey: 'id' });
        app.model.ProjectComment.belongsTo(app.model.Member, { foreignKey: 'member_id', targetKey: 'id' });
        app.model.ProjectComment.belongsTo(app.model.OrderGoods, { foreignKey: 'order_id', targetKey: 'id'});
    }
    return Model
};
